﻿@{
    ViewBag.Title = "Start";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Välkommen @Html.Raw(ViewBag.user)</h2>

<form method="post" action="/Home/NewGame">
    <input type="submit" value="Nytt Spel" />
</form>

<ul id="lobbyGamesList" data-role="listview" data-inset="true" data-icon="star">
    <li data-role="list-divider">Ej startade spel? (i Lobby):</li>
    <li>Inga lobbys funna.</li>
</ul>

<ul class="activeGamesList" data-role="listview" data-inset="true" data-icon="star">
    <li data-role="list-divider">Din tur: </li>
    @foreach (var Game in ViewBag.Games)
    {            
        <li id="@Game.GameID">
            ID : @Game.GameID
            @Html.ActionLink(" ", "ShowGame", new { gameId = Game.GameID })
            
        </li> //Länk till spelsessionen
    }
</ul>
<ul class="activeGamesList" data-role="listview" data-inset="true" data-icon="star">
    <li data-role="list-divider">Din tur: </li>
</ul>

<ul id="finishedGamesList" data-role="listview" data-inset="true" data-icon="star">
    <li data-role="list-divider">Avslutade Spel:</li>
    <li>Inga nyligen avslutade spel.</li>
</ul>

<script>

    //TODO: Polla efter dina spel (ej påbörjade, aktiva och avslutade)

    $(document).ready(
        $("#activeGamesList li").click(function (e) {

            var gameId = $(this).attr("id");
            alert($(this).attr("id") + " - (Ska visa spelets sida alt, joina dirr?)");

            $.ajax({
                url: '@Url.Content("~/Home/ShowGame")',
                data: { gameId: $(this).attr("id") },
                success: function (data) {
                }
            });

            })
        );
            //$.ajax(
            //    {
            //        type: "POST",
            //        url: "/HomeController/ShowGame",
            //        data: gameId,
            //        success : function(result)
            //        {
            //            if(result.success) //do not know yet how to have the image put in the field, even json 
            //        },
            //        error : function(req, status, error)
            //        {
            //            window.alert("Error!");   
            //        }
            //    });

</script>
